export default {
  namespaced: true,
  state: {
    fDTemp: 24, // 前舱温度 (Front cabin temperature)
    aAreaTemp: 24, // A区温度 (Zone A temperature)
    bAreaTemp: 24, // B区温度 (Zone B temperature)
    cAreaTemp: 24, // C区温度 (Zone C temperature)
    dAreaTemp: 24, // D区温度 (Zone D temperature)
    eAreaTemp: 24, // E区温度 (Zone E temperature)
    fAreaTemp: 24, // F区温度 (Zone F temperature)
    aftTemp: 7, // 后货舱温度 (Aft cargo hold temperature)
    bulkTemp: 7, // 散货舱温度 (Bulk cargo hold temperature)
    fdTrimValve: 23 // 前配平活门角度,全关是0，此时活门处于全暖位
  },
  mutations: {
    // Mutation to gradually increase the front cabin temperature to the desired value
    setFDTemp(state, value) {
      const interval = setInterval(() => {
        state.fDTemp += 1
        if (state.fDTemp >= value) {
          state.fDTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the Zone A temperature to the desired value
    setAAreaTemp(state, value) {
      const interval = setInterval(() => {
        state.aAreaTemp += 1
        if (state.aAreaTemp >= value) {
          state.aAreaTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the Zone B temperature to the desired value
    setBAreaTemp(state, value) {
      const interval = setInterval(() => {
        state.bAreaTemp += 1
        if (state.bAreaTemp >= value) {
          state.bAreaTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the Zone C temperature to the desired value
    setCAreaTemp(state, value) {
      const interval = setInterval(() => {
        state.cAreaTemp += 1
        if (state.cAreaTemp >= value) {
          state.cAreaTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the Zone D temperature to the desired value
    setDAreaTemp(state, value) {
      const interval = setInterval(() => {
        state.dAreaTemp += 1
        if (state.dAreaTemp >= value) {
          state.dAreaTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the Zone E temperature to the desired value
    setEAreaTemp(state, value) {
      const interval = setInterval(() => {
        state.eAreaTemp += 1
        if (state.eAreaTemp >= value) {
          state.eAreaTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the Zone F temperature to the desired value
    setFAreaTemp(state, value) {
      const interval = setInterval(() => {
        state.fAreaTemp += 1
        if (state.fAreaTemp >= value) {
          state.fAreaTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the aft cargo hold temperature to the desired value
    setAftTemp(state, value) {
      const interval = setInterval(() => {
        state.aftTemp += 1
        if (state.aftTemp >= value) {
          state.aftTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    // Mutation to gradually increase the bulk cargo hold temperature to the desired value
    setBulkTemp(state, value) {
      const interval = setInterval(() => {
        state.bulkTemp += 1
        if (state.bulkTemp >= value) {
          state.bulkTemp = value
          clearInterval(interval)
        }
      }, 5000)
    },
    setFDTrimValve(state, value) {
      state.fdTrimValve = value
    }
  },
  actions: {
    // Action to commit the mutation for setting the front cabin temperature
    setFDTemp(context, value) {
      context.commit('setFDTemp', value)
    },
    // Action to commit the mutation for setting the Zone A temperature
    setAAreaTemp(context, value) {
      context.commit('setAAreaTemp', value)
    },
    // Action to commit the mutation for setting the Zone B temperature
    setBAreaTemp(context, value) {
      context.commit('setBAreaTemp', value)
    },
    // Action to commit the mutation for setting the Zone C temperature
    setCAreaTemp(context, value) {
      context.commit('setCAreaTemp', value)
    },
    // Action to commit the mutation for setting the Zone D temperature
    setDAreaTemp(context, value) {
      context.commit('setDAreaTemp', value)
    },
    // Action to commit the mutation for setting the Zone E temperature
    setEAreaTemp(context, value) {
      context.commit('setEAreaTemp', value)
    },
    // Action to commit the mutation for setting the Zone F temperature
    setFAreaTemp(context, value) {
      context.commit('setFAreaTemp', value)
    },
    // Action to commit the mutation for setting the aft cargo hold temperature
    setAftTemp(context, value) {
      context.commit('setAftTemp', value)
    },
    // Action to commit the mutation for setting the bulk cargo hold temperature
    setBulkTemp(context, value) {
      context.commit('setBulkTemp', value)
    },
    setFDTrimValve(context, value) {
      if (value > 100 || value < 0) {
        console.error('前配平活门角度范围错误')
        return
      }
      context.commit('setFDTrimValve', value)
    }
  },
  getters: {
    // Getter to retrieve the front cabin temperature
    getFDTemp: (state) => state.fDTemp,
    // Getter to retrieve the Zone A temperature
    getAAreaTemp: (state) => state.aAreaTemp,
    // Getter to retrieve the Zone B temperature
    getBAreaTemp: (state) => state.bAreaTemp,
    // Getter to retrieve the Zone C temperature
    getCAreaTemp: (state) => state.cAreaTemp,
    // Getter to retrieve the Zone D temperature
    getDAreaTemp: (state) => state.dAreaTemp,
    // Getter to retrieve the Zone E temperature
    getEAreaTemp: (state) => state.eAreaTemp,
    // Getter to retrieve the Zone F temperature
    getFAreaTemp: (state) => state.fAreaTemp,
    // Getter to retrieve the aft cargo hold temperature
    getAftTemp: (state) => state.aftTemp,
    // Getter to retrieve the bulk cargo hold temperature
    getBulkTemp: (state) => state.bulkTemp,
    // Getter to retrieve the front cabin trim valve angle
    getFDTrimValve: (state) => state.fdTrimValve
  }
}
